package com.data241210.SpringbootDemo.mapper;

import com.data241210.SpringbootDemo.model.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Student表的Mapper类
 */
@Mapper //注解的方式使用mybatis
public interface StudentMapper {
    //查询全部数据
    @Select("SELECT * FROM student")
    public List<Student> findAll(); //空方法，实际实现由mybatis完成

    //保存插入数据
    @Insert("insert into student(sno,sname,sex,age,address) values(#{sno},#{sname},#{sex},#{age},#{address})")
    public int save(Student student);

    //删除数据
    @Delete("delete from student where sno=#{sno}")
    int delete(Integer sno);

    //按学号查找数据
    @Select("select * from student where sno=#{sno}")
    Student findBySno(Integer sno);

    //更新数据
    @Update("update student set sname=#{sname},sex=#{sex},age=#{age},address=#{address} where sno=#{sno}")
    int update(Student student);

    List<Student> findByName(String sname);
}
